package 算法.leetcode.linked.list;

import org.junit.Test;

/**
 * @author lchenglong
 * @date 2021/1/5
 */
public class MiddleNode extends LinkListBase {

    @Test
    public void test() {
        int[] arr = new int[]{1, 2, 3, 4};
        ListNode head = createTestData(arr);
        head = middleNode(head);
        toString(head);
    }

    public ListNode middleNode(ListNode head) {
        ListNode fast = head;
        ListNode slow = head;
        while (fast != null && fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;
        }
        return slow;
    }
}
